function createForm(data,name,container){//表单
    let checkbox = '';
    for(let i=0;i<data.length;i++){
        checkbox += `<input type="checkbox" name="${name}" value="${data[i]}" />${data[i]} `
    }
    checkbox = `<input type="checkbox" name="sel${name}" class="all" onclick="selectAll(sel${name})"/>全选/取消全选 ${checkbox}`;
    document.getElementById(container).innerHTML = checkbox;
}
function selectAll(e){//全选逻辑
    switch(e.name) {
            case 'selarea':
                for(let i =0;i<sarea.length;i++){
                    if(e.checked){
                        sarea[i].checked = true;
                    }else{
                        sarea[i].checked = false;
                    }
                }
               
                break;
            case 'selgoods':
                for(let i =0;i<sgoods.length;i++){
                    if(e.checked){
                        sgoods[i].checked = true;

                    }else{
                        sgoods[i].checked = false;
                    }
                }
                break;
        } 
    let areaValues = getAreaVales();//选地区中的值
    let goodsValues = getGoodsVales();//选中商品的值
    createTbody(areaValues,goodsValues);
}
sform.addEventListener('click',function(e){//复选框逻辑
    if(e.target.nodeName.toLowerCase() == 'input'&& e.target.name.toLowerCase() == 'area' || e.target.name.toLowerCase() == 'goods'){
        let areaValues = getAreaVales();//选地区中的值
        let goodsValues = getGoodsVales();//选中商品的值 
        console.log(areaValues,goodsValues)
        if(areaValues.length<1 || goodsValues<1){
            e.target.checked = true;
            return
        }
        if(areaValues.length == 3){
            all[0].checked = true;
        }else if(areaValues.length <3){
            all[0].checked = false;
        }
        if(goodsValues.length == 3){
            all[1].checked = true;
        }else if(goodsValues.length <3){
            all[1].checked = false;
        }
        createTbody(areaValues,goodsValues);
    }
})
function getAreaVales(){//获取选中地区返回值
    var values = [];
    for(let i=0;i<sarea.length;i++){
        if(sarea[i].checked){
            values.push(sarea[i].value);
        }
    }
    return values;
}
function getGoodsVales(){//获取选中商品返回值
    var values = [];
    for(let i=0;i<sgoods.length;i++){
        if(sgoods[i].checked){
            values.push(sgoods[i].value);
        }
    }
    return values
}